import {ClassicModel} from "../../models/classic" ;
import {LikeModel} from "../../models/like";
const classicmodel=new ClassicModel();
const likeModel=new LikeModel();
Page({
  data: {
  classic:{},
  isLatest:true,
  isFirst:false
  },
  onLoad: function (options) {
        classicmodel.getLatest(res=>{
           this.setData({
             classic:res,
             like:res.like_status,
             count:res.fav_nums
           })
        })
  },
  onLike(e){
    // console.log(e.detail)
    var behavior=e.detail.behavior;
    var id=this.data.classic.id;
    var type=this.data.classic.type;
    likeModel.getLike(behavior,id,type);
  },

onPrev(){
  this._updateData("previous");
},
onNext(){
 this._updateData("next");
},
_updateData(nextOrprevious){
     classicmodel.getClassic(this.data.classic.index,nextOrprevious,res=>{
       likeModel.getLikeStatus(res.type,res.id,res=>{
         this.setData({
           like:res.like_status,
           count:res.fav_nums
         })
       })
    this.setData({
      classic:res,
      isFirst:classicmodel.isFirst(res.index),
      isLatest:classicmodel.isLatest(res.index)
    })
  })
},
onShareAppMessage(){
  console.log(1);
},
})